﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    >

    <Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
    </Style>

    <DataTemplate DataType="{x:Type vm:SettingsViewModel}">
        <DataTemplate.Resources>
            <Thickness x:Key="ButtonMargin" Left="{x:Static c:UX.ButtonSeparatorWidth}" Top="{x:Static c:UX.DialogPadding}"/>
        </DataTemplate.Resources>

        <Grid Margin="{x:Static c:UX.DialogPaddingThickness}">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TabControl Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" ItemsSource="{Binding Pages}" IsSynchronizedWithCurrentItem="True">
                <TabControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Header}"/>
                    </DataTemplate>
                </TabControl.ItemTemplate>
            </TabControl>
            <Button Grid.Row="1" Grid.Column="1" Content="{c:LocalizedString s_OK}" IsDefault="True" Command="{Binding SaveCommand}" MinWidth="{x:Static c:UX.ButtonWidth}" Margin="{StaticResource ButtonMargin}"/>
            <Button Grid.Row="1" Grid.Column="2" Content="{c:LocalizedString s_Cancel}" IsCancel="True" Command="{Binding CloseCommand}" MinWidth="{x:Static c:UX.ButtonWidth}" Margin="{StaticResource ButtonMargin}"/>
            <Button Grid.Row="1" Grid.Column="3" Content="{c:LocalizedString s_Apply}" Command="{Binding ApplyCommand}" MinWidth="{x:Static c:UX.ButtonWidth}" Margin="{StaticResource ButtonMargin}"/>
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type vm:UiSettingsPageViewModel}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Label Grid.Row="0" Grid.Column="0" Content="{c:LocalizedString s_Label_Language}" VerticalAlignment="Center"/>
            <ComboBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding UiLanguages}" SelectedValuePath="Language" SelectedValue="{Binding Path=UiLanguage, Mode=TwoWay}" VerticalAlignment="Center" MinWidth="100">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Label Grid.Row="1" Grid.Column="0" Content="{c:LocalizedString s_Label_Theme}" VerticalAlignment="Center"/>
            <ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Themes}" SelectedValuePath="ID" SelectedValue="{Binding Path=ThemeID, Mode=TwoWay}" VerticalAlignment="Center" MinWidth="120">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <StackPanel Grid.Row="2" Grid.ColumnSpan="3" Orientation="Horizontal">
                <Label Content="{c:LocalizedString s_SendMessageGesture}" VerticalAlignment="Center"/>
                <TextBox Text="{Binding Path=SendMessageGesture, Mode=TwoWay, Converter={x:Static cnv:KeyGestureValueConverter.Default}}" MinWidth="100" VerticalAlignment="Center"/>
            </StackPanel>

            <CheckBox Grid.Row="3" Grid.ColumnSpan="3" Content="{c:LocalizedString s_ShowMessageTime}" HorizontalAlignment="Left" IsChecked="{Binding Path=ShowMessageTime, Mode=TwoWay}"/>

            <CheckBox Grid.Row="4" Grid.ColumnSpan="3" Content="{c:LocalizedString s_SendTypingNotifications}" HorizontalAlignment="Left" IsChecked="{Binding Path=SendTypingNotifications, Mode=TwoWay}"/>
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type vm:ConnectionSettingsPageViewModel}">
        <StackPanel>
            <CheckBox x:Name="useDefaults" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" IsChecked="{Binding Path=UseDefaultConnectionSettings, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Content="{c:LocalizedString s_UseDefaultConnectionSettings}"/>
            <Grid x:Name="customConnectionSettings">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Label Grid.Row="0" Grid.Column="0" Content="{c:LocalizedString s_TextChatServer}" VerticalAlignment="Center"/>
                <ComboBox Grid.Row="0" Grid.Column="1" IsEditable="True" IsReadOnly="False" HorizontalAlignment="Stretch" ItemsSource="{Binding Servers}" Text="{Binding Path=TextChatServer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" MinWidth="200"/>

                <Label Grid.Row="1" Grid.Column="0" Content="{c:LocalizedString s_BaseServer}" VerticalAlignment="Center"/>
                <ComboBox Grid.Row="1" Grid.Column="1" IsEditable="True" IsReadOnly="False" HorizontalAlignment="Stretch" ItemsSource="{Binding Servers}" Text="{Binding Path=BaseServer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" MinWidth="200"/>
            </Grid>
        </StackPanel>
        <DataTemplate.Triggers>
            <Trigger SourceName="useDefaults" Property="IsChecked" Value="True">
                <Setter TargetName="customConnectionSettings" Property="IsEnabled" Value="False"/>
            </Trigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate DataType="{x:Type vm:TranslatorSettingsPageViewModel}">
        <StackPanel Orientation="Vertical">
            <CheckBox Content="{c:LocalizedString s_IsTranslatorActive}" IsChecked="{Binding Path=IsActive, Mode=TwoWay}" HorizontalAlignment="Left"/>
            <ComboBox x:Name="translatorsComboBox" ItemsSource="{Binding Translators}" SelectedValuePath="ID" SelectedValue="{Binding Path=TranslatorID, Mode=TwoWay}" HorizontalAlignment="Left" IsEditable="False" MinWidth="150">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <GroupBox x:Name="targetLanguageGroupBox" Header="{c:LocalizedString s_TargetLanguage}" HorizontalAlignment="Left">
                <StackPanel Orientation="Vertical">
                    <CheckBox Content="{c:LocalizedString s_UiLanguage}" IsChecked="{Binding Path=IsUiLanguageTarget, Mode=TwoWay}"/>
                    <ComboBox x:Name="targetLanguagesComboBox" ItemsSource="{Binding Path=SupportedTargetLanguages, Converter={x:Static cnv:LanguageListSortingConverter.Default}}" SelectedItem="{Binding Path=TargetLanguage, Mode=TwoWay}" HorizontalAlignment="Left" IsEditable="False" MinWidth="140">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Converter={x:Static cnv:LanguagesConverter.Default}}"/>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </StackPanel>
            </GroupBox>
        </StackPanel>
        
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsActive}" Value="False">
                <Setter TargetName="translatorsComboBox" Property="IsEnabled" Value="False"/>
                <Setter TargetName="targetLanguageGroupBox" Property="IsEnabled" Value="False"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsUiLanguageTarget}" Value="True">
                <Setter TargetName="targetLanguagesComboBox" Property="IsEnabled" Value="False"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate DataType="{x:Type vm:NotificationSettingsPageViewModel}">
        <ItemsControl ItemsSource="{Binding Settings}" HorizontalAlignment="Left" VerticalAlignment="Top">
            <ItemsControl.Resources>
                <DataTemplate DataType="{x:Type vm:SoundNotifierSettingsViewModel}">
                    <GroupBox>
                        <GroupBox.Header>
                            <CheckBox IsChecked="{Binding Path=IsActive, Mode=TwoWay}" Content="{c:LocalizedString s_SoundNotification}"/>
                        </GroupBox.Header>
                        <StackPanel Orientation="Vertical">
                            <CheckBox IsChecked="{Binding Path=NotifyOnMessagesInActiveChatWindows, Mode=TwoWay}" Content="{c:LocalizedString s_NotifyOnMessagesInActiveChatWindows}"/>
                            <CheckBox IsChecked="{Binding Path=NotifyOnPublicChatMessages, Mode=TwoWay}" Content="{c:LocalizedString s_NotifyOnPublicChatMessages}"/>
                        </StackPanel>
                    </GroupBox>
                </DataTemplate>

                <DataTemplate DataType="{x:Type vm:FlashWindowNotifierSettingsViewModel}">
                    <GroupBox>
                        <GroupBox.Header>
                            <CheckBox IsChecked="{Binding Path=IsActive, Mode=TwoWay}" Content="{c:LocalizedString s_FlashWindowNotification}"/>
                        </GroupBox.Header>
                        <StackPanel Orientation="Vertical">
                            <CheckBox IsChecked="{Binding Path=NotifyOnMessagesInActiveChatWindows, Mode=TwoWay}" Content="{c:LocalizedString s_NotifyOnMessagesInActiveChatWindows}"/>
                            <CheckBox IsChecked="{Binding Path=NotifyOnPublicChatMessages, Mode=TwoWay}" Content="{c:LocalizedString s_NotifyOnPublicChatMessages}"/>
                        </StackPanel>
                    </GroupBox>
                </DataTemplate>

                <DataTemplate DataType="{x:Type vm:BalloonTipNotifierSettingsViewModel}">
                    <GroupBox>
                        <GroupBox.Header>
                            <CheckBox IsChecked="{Binding Path=IsActive, Mode=TwoWay}" Content="{c:LocalizedString s_BalloonTipNotification}"/>
                        </GroupBox.Header>
                        <StackPanel Orientation="Vertical">
                            <CheckBox IsChecked="{Binding Path=NotifyOnMessagesInActiveChatWindows, Mode=TwoWay}" Content="{c:LocalizedString s_NotifyOnMessagesInActiveChatWindows}"/>
                            <CheckBox IsChecked="{Binding Path=NotifyOnPublicChatMessages, Mode=TwoWay}" Content="{c:LocalizedString s_NotifyOnPublicChatMessages}"/>
                        </StackPanel>
                    </GroupBox>
                </DataTemplate>
            </ItemsControl.Resources>
        </ItemsControl>
    </DataTemplate>

</ResourceDictionary>